<!DOCTYPE html>
<!--
 Copyright (c) 2019 Proton Technologies AG

 This file is part of ProtonVPN.

 ProtonVPN is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 ProtonVPN is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ProtonVPN.  If not, see <https://www.gnu.org/licenses/>.
-->
<html>
<head>
    <style>
        body {
            background: #17181C;
            color: white;
            margin: 0px;
        }

        .container {
            font-weight: bold;
            word-wrap: break-word;
        }

        h1 {
            font-family: Roboto;
            font-size: 14px;
            font-style: normal;
            font-weight: 500;
            line-height: 20px;
            letter-spacing: 0.25px;
            margin: 0px 16px;
            padding-top: 24px;
            padding-bottom: 0px;
        }

        .row {
            display: flex;
            justify-content: space-between;
            font-size: small;
            padding: 12px 16px;
            border-bottom: 1px solid #303239;

            //styleName: Body 2 / body-2-regular;
            font-family: Roboto;
            font-size: 14px;
            font-style: normal;
            font-weight: 400;
            line-height: 20px;
            letter-spacing: 0.25px;
        }

        .label {
            color: #9CA0AA;
            min-width: 5em;
        }

        .licenses {
            padding: 12px 16px;

            // styleName: Caption / caption-regular;
            font-family: Roboto;
            font-size: 12px;
            font-style: normal;
            font-weight: 400;
            line-height: 16px;
            letter-spacing: 0.4000000059604645px;
            text-align: left;
        }

        .licensesLabel {
            color: #9CA0AA;
            // styleName: Body 2 / body-2-regular;
            font-family: Roboto;
            font-size: 14px;
            font-style: normal;
            font-weight: 400;
            line-height: 20px;
            letter-spacing: 0.25px;
        }

        a {
            text-decoration: none;
            color: #8A6EFF;
        }

        a.icon {
            display: inline;
            margin-left: 0.5em;
        }

        a.icon img {
            position: relative;
            top: -2px;
            vertical-align: middle;
        }
    </style>
</head>
<body>
    <script src="open_source_licenses.js"></script>
    <script src="extra_licenses.js"></script>

    <script>
        fixes = {
            "circleprogress": {
                "url": "https://github.com/lzyzsd/CircleProgress",
                "licenses": [
                    {
                        "license": "https://github.com/lzyzsd/CircleProgress/blob/master/README.md",
                        "license_url": "https://github.com/lzyzsd/CircleProgress/blob/master/README.md"
                    }
                ]
            },
            "core": {
                "url": "https://github.com/afollestad/material-dialogs",
                "licenses": [
                    {
                        "license": "Apache License 2.0",
                        "license_url": "https://github.com/afollestad/material-dialogs/blob/master/LICENSE.md"
                    }
                ]
            },
            "jdk9-deps": { // No license, compile-time dependency
                "url": "https://github.com/pengrad/jdk9-deps"
            },
            "keyboardvisibilityevent": {
                "url": "https://github.com/yshrsmz/KeyboardVisibilityEvent",
                "licenses": [
                    {
                        "license": "Apache License 2.0",
                        "license_url": "https://github.com/yshrsmz/KeyboardVisibilityEvent/blob/master/LICENSE"
                    }
                ]
            },
            "MPAndroidChart": {
                "url": "https://github.com/PhilJay/MPAndroidChart",
                "licenses": [
                    {
                        "license": "Apache License 2.0",
                        "license_url": "https://github.com/PhilJay/MPAndroidChart/blob/master/LICENSE"
                    }
                ]
            },
            "RxActivityResult": {
                "url": "https://github.com/VictorAlbertos/RxActivityResult",
                "licenses": [
                    {
                        "license": "Apache License 2.0",
                        "license_url": "https://github.com/VictorAlbertos/RxActivityResult/blob/2.x/LICENSE.txt"
                    }
                ]
            },
            "shts/TriangleLabelView": {
                "licenses": [
                    {
                        "license": "Apache License 2.0",
                        "license_url": "https://github.com/shts/TriangleLabelView#license"
                    }
                ]
            },
            "tileview": {
                "url": "https://github.com/moagrius/TileView",
                "licenses": [
                    {
                        "license": "MIT License",
                        "license_url": "https://github.com/moagrius/TileView/blob/master/LICENSE"
                    }
                ]
            },
        };

        function applyFixes(dependencies) {
            for (var i in dependencies) {
                var dependency = dependencies[i];

                if (dependency.url === null) {
                    if (dependency.project in fixes && "url" in fixes[dependency.project])
                        dependency.url = fixes[dependency.project].url;
                }

                if (dependency.licenses.length == 0) {
                    if (dependency.project in fixes && "licenses" in fixes[dependency.project])
                        dependency.licenses = fixes[dependency.project].licenses;
                }
            }
        }

        function createLabelWithValue(labelText, valueText) {
            var row = document.createElement('div');
            row.className = 'row';
            var versionLabel = document.createElement('span')
            versionLabel.className = 'label';
            versionLabel.innerText = labelText
            var versionValue = document.createElement('span')
            versionValue.className = 'value';
            versionValue.innerText = valueText;
            row.appendChild(versionLabel);
            row.appendChild(versionValue);
            return row;
        }

        function processDependencies(dependencies) {
            for (var i in dependencies) {
                var dependency = dependencies[i];
                var elem = document.createElement('div');
                elem.className = 'container';
                var header = document.createElement('h1');
                header.innerText = dependency.project
                elem.appendChild(header);

                if (dependency.url !== null) {
                    var icon = document.createElement('img');
                    icon.src = 'ic-arrow-out-square.svg'
                    var link = document.createElement('a');
                    link.className = 'icon';
                    link.href = dependency.url;
                    link.appendChild(icon);
                    header.appendChild(link);
                }

                if (dependency.version !== null) {
                    elem.appendChild(createLabelWithValue('Version:', dependency.version));
                }

                if (dependency.developers.length > 0) {
                    elem.appendChild(createLabelWithValue('By:', dependency.developers.join(', ')));
                }

                if (dependency.licenses.length > 0) {
                    var licensesBlock = document.createElement('div');
                    licensesBlock.className = 'licenses';
                    var licensesLabel = document.createElement('div');
                    licensesLabel.className = 'licensesLabel';
                    licensesLabel.innerText = 'Licenses:'
                    licensesBlock.appendChild(licensesLabel);
                    for (j in dependency.licenses) {
                        var license = dependency.licenses[j];
                        var licenseElem = document.createElement('a');
                        licenseElem.href = license.license_url;
                        licenseElem.innerText = license.license;
                        licensesBlock.appendChild(licenseElem);
                    }
                    elem.appendChild(licensesBlock);
                }
                
                document.body.appendChild(elem);
            }
        }

        applyFixes(dependencies);
        processDependencies(dependencies);
        processDependencies(extraDependencies);
    </script>
</body>
</html>
